package com.itcm.cloudStudy.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 描述:
 *
 * @author cm_fighting
 * @create 2020-08-20 10:53 上午
 */
@Slf4j
@RestController
public class FlowLimitController {

    @GetMapping("/testA")
    public String testA() {
//        try {
//            Thread.sleep(800);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        log.info(Thread.currentThread() + "\ttestA");
        return "---------testA";
    }

    @GetMapping("/testB")
    public String testB() {
        log.info(Thread.currentThread() + "\ttestB");
        return "---------testB";
    }

    // 测试热点限流
    @GetMapping("/testHotKey")
    @SentinelResource(value = "testHotKey", blockHandler = "deal_testHotKey")
    public String testHotKey(@RequestParam(value = "p1", required = false) String p1,
                             @RequestParam(value = "p2", required = false) String p2) {
//        int age = 10 / 0;
        return "**** test hot key ****";
    }

    public String deal_testHotKey(String p1, String p2, BlockException blockException) {
        return "**** test hot key **** o(╥﹏╥)o";
    }
}
